package org.Image.management.ViewService.Game.pojo;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Data
public class TableImage {
    private final String noteText; //备注文本

    //-----需求-----
    private final Image image;
    private final Button setup = new Button("查看");
    private final Button revise = new Button("修改");
    private final Button det = new Button("删除");
    private final Label noteLabel = new Label();

    //-----提供------- #记得提供get的方法
    private HBox HImage;//图片预览
    private HBox operatorButton; //设置按钮
    private HBox noteTextLabel; //备注文本标签


    public TableImage(Image image, EventHandler<ActionEvent> reviseActionEvent, EventHandler<ActionEvent> setupActionEvent, EventHandler<ActionEvent> detActionEvent, String remark, EventHandler<MouseEvent> remarkMouseClicked) {
        this.image = image;
        noteText = remark;
        setup.setOnAction(setupActionEvent);
        revise.setOnAction(reviseActionEvent);
        det.setOnAction(detActionEvent);

        noteLabel.setOnMouseClicked(remarkMouseClicked);
        addData();
    }


    //数据
    private void addData() {
        //-----------------设置HImage-------------------------------
        HImage = new HBox();
        if (image != null) {
            ImageView view = new ImageView(image);
            view.setPreserveRatio(true);

            view.setFitWidth(150);

            HImage.getChildren().addAll(view);
        }

        //设置居中
        HImage.setAlignment(Pos.CENTER);

        //-----------------设置operatorButton-----------------------
        operatorButton = new HBox(setup, revise, det);
        //设置居中
        operatorButton.setAlignment(Pos.CENTER);

        //-----------------设置noteTextLabel-----------------------
        noteTextLabel = new HBox();

        noteLabel.setFont(new Font(16));
        noteLabel.setText(noteText);

        if (noteText == null || noteText.isEmpty() || noteText.isBlank()) {
            noteLabel.setTextFill(Color.web("#0038f5"));
            noteLabel.setUnderline(true);
            noteLabel.setText("点击添加文本");
            noteLabel.setFont(new Font(15));

        }
        noteTextLabel.setAlignment(Pos.CENTER);
        noteTextLabel.getChildren().addAll(noteLabel);
    }


}
